package com.controller;

import com.entity.PageInfo;
import com.entity.SchPlan;
import com.entity.SchPlanQueryTime;
import com.github.pagehelper.PageHelper;
import com.service.ISchPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;

@Api(tags = "调度计划信息")
@RestController
@RequestMapping("/scheduler")
public class SchPlanController {

    @Autowired
    private ISchPlanService iSchPlanService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",dataType = "int",value = "页数",paramType = "query",required = true,defaultValue = "1"),
            @ApiImplicitParam(name = "rows",dataType = "int",value = "每条页数",paramType = "query",required = true,defaultValue = "10"),
            @ApiImplicitParam(name = "planId",dataType = "String",value = "调度计划编号",paramType = "query",required = false),
            @ApiImplicitParam(name = "planName",dataType = "String",value = "调度计划名称",paramType = "query",required = false),
            @ApiImplicitParam(name = "planType",dataType = "String",value = "调度计划类别",paramType = "query",required = false),
            @ApiImplicitParam(name = "beginTime",dataType = "String",value = "调度计划创建开始时间",paramType = "query",required = false),
            @ApiImplicitParam(name = "endTime",dataType = "String",value = "调度计划创建结束时间",paramType = "query",required = false),
    })

    @ApiOperation(value = "查询计划信息",response = SchPlan.class)
    @RequestMapping(value = "/plans",method = RequestMethod.GET)
    public PageInfo<SchPlan> query(@ApiIgnore SchPlanQueryTime record){
        System.out.println(record);
        PageHelper.startPage(record.getPage(),record.getRows());
        List<SchPlan> schPlanList = iSchPlanService.query(record);
        PageInfo<SchPlan> schPlanPageInfo = new PageInfo<>(schPlanList);
        return schPlanPageInfo;
    }

    @ApiOperation(value = "新增计划信息",response = Integer.class)
    @RequestMapping(value = "/plans",method = RequestMethod.POST)
    public Object insert(@RequestBody SchPlan schPlan){
        iSchPlanService.insert(schPlan);
        return "success";
    }

    @ApiOperation(value = "删除计划信息",response = Integer.class)
    @RequestMapping(value = "/plans/{id}",method = RequestMethod.DELETE)
    public Object delete(@PathVariable int id){
        iSchPlanService.delete(id);
        return "success";
    }

    @ApiOperation(value = "修改计划信息",response = SchPlan.class)
    @RequestMapping(value = "/plans/{id}",method = RequestMethod.PUT)
    public Object update(@RequestBody SchPlan schPlan){
        iSchPlanService.update(schPlan);
        return "success";
    }
}
